<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="门牌号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="houseNo">
              <a-input v-model="model.houseNo" placeholder="请输入门牌号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="面积" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="areaMeasure">
              <a-input v-model="model.areaMeasure" placeholder="请输入面积"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收房日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkinDate">
              <a-input v-model="model.checkinDate" placeholder="请输入收房日期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="state">
              <a-input v-model="model.state" placeholder="请输入状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="户主" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="holder">
              <a-input v-model="model.holder" placeholder="请输入户主"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mobile">
              <a-input v-model="model.mobile" placeholder="请输入联系电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="小区id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="villageId">
              <j-dict-select-tag type="list" v-model="model.villageId" dictCode="property_village,name,id" placeholder="请选择小区id" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="楼栋id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="buildindId">
              <j-dict-select-tag type="list" v-model="model.buildindId" dictCode="property_building,name,id" placeholder="请选择楼栋id" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'PropertyHouseForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           houseNo: [
              { required: true, message: '请输入门牌号!'},
           ],
           areaMeasure: [
              { required: true, message: '请输入面积!'},
           ],
           state: [
              { required: true, message: '请输入状态!'},
           ],
           villageId: [
              { required: true, message: '请输入小区id!'},
           ],
           buildindId: [
              { required: true, message: '请输入楼栋id!'},
           ],
        },
        url: {
          add: "/properties.house/propertyHouse/add",
          edit: "/properties.house/propertyHouse/edit",
          queryById: "/properties.house/propertyHouse/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>